package com.augurit.wf.mgmt.web;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.wf.mgmt.service.IWfProcessInstanceService;
import com.augurit.wf.mgmt.web.form.Jbpm4VariableForm;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "wf-process-variable.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/wf/mgmt/process-instance/process-instance-mgmt.jsp")
})
public class WfProcessVariableAction extends ExtCrudActionSupport<Jbpm4VariableForm> {

	private Jbpm4VariableForm form;
	private Page<Jbpm4VariableForm> page = new Page<Jbpm4VariableForm>(15);
	
	private Long[] varDbids;//变量dbid数组
	
	@Autowired
	private IWfProcessInstanceService wfProcessInstanceService;

	@Override
	public String list() throws Exception {
		return null;
	}
	
	public String saveVariable() throws Exception{
		if(form != null)
			wfProcessInstanceService.saveVariable(form);
			WfProcessVariableAction.extRenderSuccess();
		return null;
	}
	
	public String deleteVariables() throws Exception{
		if(this.varDbids != null && this.varDbids.length > 0){
			wfProcessInstanceService.deleteVariables(varDbids);
			WfProcessVariableAction.extRenderSuccess();
		}
		return null;
	}
	
	public String getVariable() throws Exception{
		if(form != null && form.getDbid() != null){
			form = wfProcessInstanceService.getVariable(form.getDbid());
			WfProcessVariableAction.extRenderFormJson(form);
		}
		return null;
	}
	
	//******************流程实例控制  结束******************
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (form == null)
			form = new Jbpm4VariableForm();
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public Jbpm4VariableForm getModel() {
		// TODO Auto-generated method stub
		return form;
	}

	public Page<Jbpm4VariableForm> getPage() {
		return page;
	}

	public void setPage(Page<Jbpm4VariableForm> page) {
		this.page = page;
	}

	public Jbpm4VariableForm getForm() {
		return form;
	}

	public void setForm(Jbpm4VariableForm form) {
		this.form = form;
	}

	public Long[] getVarDbids() {
		return varDbids;
	}

	public void setVarDbids(Long[] varDbids) {
		this.varDbids = varDbids;
	}
	
}
